import { getDefaultPaywallConfig } from '@constants/paywall.ts';
import { createSlice } from '@reduxjs/toolkit';

interface PaywallState {
  paywallProductDetailList: Payment.ProductDetailInstance[];
  paywallConfig: Paywall.PaywallConfig;
  paywallRouteName: string;
}

const initialState: PaywallState = {
  paywallProductDetailList: [],
  paywallConfig: getDefaultPaywallConfig(),
  paywallRouteName: getDefaultPaywallConfig()?.subscriptionRoute.name,
};

export const paywallSlice = createSlice({
  name: 'paywall',
  initialState,
  reducers: {
    setPaywallProductDetailList: (state, action) => {
      state.paywallProductDetailList = action.payload;
    },
    setPaywallConfig: (state, action) => {
      state.paywallConfig = action.payload;
    },
    setPaywallRouteName: (state, action) => {
      state.paywallRouteName = action.payload;
    },
  },
});

export const { setPaywallProductDetailList, setPaywallConfig, setPaywallRouteName } = paywallSlice.actions;
